<template>
    <div class="pingjia-wrap">
        <div class="title-warp">
            {{Title}}
        </div>
        <div v-if="RoleCode=='User'&&entranceType=='pingjia'&&CStatus==0" class="container-top" v-for="(item,index) in dataList" :key="index">
            <div class="title">
                <div class="left">&nbsp;</div>
                <p>{{item.ItemName}}</p>
            </div>
            <div class="select">
                <div  @click="selectFn(item,1)"><span :class="item.Score==1?'select-in-the':''"></span>非常满意</div>
                <div  @click="selectFn(item,2)"><span :class="item.Score==2?'select-in-the':''"></span>满意</div>
                <div  @click="selectFn(item,3)"><span :class="item.Score==3?'select-in-the':''"></span>一般</div>
            </div>
        </div>
        <div v-if="RoleCode == 'Expert'||RoleCode == 'Leader'||entranceType=='report'||CStatus>0" class="container-top" v-for="(item,keyId) in dataList" :key="keyId">
            <div class="title">
                <div class="left">&nbsp;</div>
                <p>{{item.TName}}{{RoleCode == 'User'&&entranceType == 'pingjia'?'':'('+ item.EvaluationSatisfaction+'%)'}}</p>
            </div>
            <div class="select">
                <div>非常满意({{item.FCMYCount}})</div>
                <div>满意({{item.MYCount}})</div>
                <div>一般({{item.YBCount}})</div>
            </div>
        </div>
        <button v-if="RoleCode=='User'&&entranceType=='pingjia'&&CStatus=='0'" @click="submitFn" class="button">提交</button>
        <van-toast id="van-toast" />
    </div>
</template>

<script>
    import {
        TrainingRuleList,
        EvaluationAdd,
        EvalationDetail,
        GetTrainingOtherEvaluationInfo
    } from '@/providers/service'
    export default {
        name: 'my/changePassword',
        data() {
            return {
                dataList: [],
                value: '',
                TID: '',
                Title: '',
                UserID: '',
                RoleCode: '',
                OtherCourseID: '',
                TType:'',
                ID: '',
                entranceType: '',
                CStatus: '',
                TrainingAssessmentTypeID: ''
            }
        },
        onLoad() {
            let {
                TID,
                OtherCourseID,
                Title,
                entranceType,
                CStatus,
                ID,
                TType
            } = this.$route.query;
            this.TID = TID
            this.ID = ID
            this.TType = TType
            this.Title = Title
            this.OtherCourseID = OtherCourseID
            this.entranceType = entranceType
            this.CStatus = CStatus
            this.RoleCode = wx.getStorageSync('userInfo').RoleCode
            this.UserID = wx.getStorageSync('userInfo').UserID
        },
        onShow() {
            if (this.RoleCode == 'Expert' || this.RoleCode == 'Leader') {
                this.EvalationDetailApi() //专家或领导
            } else if (this.RoleCode == 'User' && this.entranceType == 'pingjia' && this.CStatus == 0) {
                this.TrainingRuleListGet() // 学员
            } else if ((this.RoleCode == 'User' && this.entranceType == 'report') || (this.RoleCode == 'User' && this.CStatus > 0)) {
                this.EvalationDetailApi()
            }
        },
        methods: {
            selectFn(data, type) {
                this.$nextTick(() => {
                    data.Score = type
                    this.dataList
                })
            },
            submitFn() {
                this.evaluationAddFn()
            },
            // 查询课程评价详情
            async EvalationDetailApi() {
                try {
                    let res = await EvalationDetail({
                        TID: this.TID,
                        Type:1,
                        UserID: this.UserID,
                        OtherCourseID: this.OtherCourseID
                    })
                    this.dataList = res
                } catch (error) {}
            },
            // 项目总结新增编辑
            async evaluationAddFn() {
                try {
                    let curData = JSON.parse(JSON.stringify(this.dataList))
                    for (let item of curData) {
                        if (item.Score == '') {
                            this.$toast(item.ItemName + '不能为空')
                            return false
                        }
                        delete item.ItemName
                        delete item.TrainingAID
                        delete item.Type
                    }
                    console.log(curData)
                    let res = await EvaluationAdd(curData)
                    if (!res) {
                        this.$toast('提交评价成功')
                        setTimeout(() => {
                            this.$router.go(-1)
                        }, 1000)
                    }
                } catch (error) {
                    console.log(error)
                }
            },
            //  项目评价详情
            async TrainingRuleListGet() {
                try {
                    let res = await TrainingRuleList({
                        TID: this.TID,
                        Type: 1
                    })
                    this.backData(res)
                } catch (error) {
                    console.log(error)
                }
            },
            // 领导或专家时候展示的数据
            async GetTrainingOtherEvaluationInfoApi() {
                try {
                    let res = await GetTrainingOtherEvaluationInfo({
                        TID: this.TID,
                        Type:1,
                        UserID: this.UserID,
                        OtherCourseID: this.OtherCourseID
                    })
                    this.dataList = res
                } catch (error) {
                    console.log(error)
                }
            },
            //返回数据重组
            backData(originDate) {
                let {
                    ExpertID
                } = this.$route.query;
                let arr = []
                let objData = {
                    TID: this.TID,
                    Type:1,
                    UserID: this.UserID,
                    CreateBy: this.UserID,
                    Score: '',
                    ExpertID,
                    OtherCourseID: this.OtherCourseID
                }
                let index = 1
                for (let item of originDate) {
                    objData.TrainingAssessmentTypeID = item.TrainingAID
                    objData.TrainingAID = item.TrainingAID
                    objData.ItemName = item.ItemName
                    let clone = JSON.parse(JSON.stringify(objData))
                    arr.push(clone)
                    index = index + 1
                }
                this.dataList = arr
                arr = []
            }
        },
        created() {},
    }
</script>

<style lang="less" scoped>
    page {
        height: 100%;
        width: 100%;
    }
    .pingjia-wrap {
        .title-warp {
            font-size: 38rpx;
            color: #000;
            font-weight: 700;
            margin-top: 70rpx;
            padding: 0rpx 100rpx 0 40rpx;
            width: 100%;
            box-sizing: border-box;
        }
        width: 100%;
        height: 100%;
        .select {
            display: flex;
            flex-direction: row;
            margin: 50rpx 0 0rpx 40rpx;
            text-align: center;
            >div {
                >span {
                    display: inline-block;
                    width: 26rpx;
                    height: 26rpx;
                    border-radius: 50%;
                    border: 2rpx solid #c9c9c9;
                    margin-right: 16rpx;
                }
                color: #333;
                font-size: 16px;
                line-height: 20px;
                flex: 1
            }
        }
        .title {
            width: 100%;
            height: 90rpx;
            display: flex;
            margin: 50rpx;
            font-size: 34rpx;
            font-weight: 600;
            .left {
                width: 8rpx;
                height: 100%;
                background: #01a783;
            }
            p {
                margin: 0 100rpx 0 30rpx;
            }
        }
        .button {
            width: 322rpx;
            height: 92rpx;
            line-height: 92rpx;
            margin-top: 140rpx;
            font-size: 36rpx;
            border-radius: 0px;
            color: #FFF;
            background: #01a783;
        }
    }
    .select-in-the {
        background: #01a783;
        border: 2rpx solid #ffffff;
    }
</style>